package com.edu.exam.entity.examination.paper;

import com.edu.exam.enums.AssignmentConflictType;
import com.edu.exam.enums.AssignmentConflictSeverity;
import com.edu.exam.enums.AssignmentConflictStatus;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 监考安排冲突实体类
 * 所属模块：E-01 考试执行模块
 * 对应数据库表：assignment_conflict
 *
 * <p>监考安排冲突实体，记录监考安排中的冲突情况。
 * 包含冲突类型、严重程度、解决方案等详细信息。</p>
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AssignmentConflict {

    /**
     * 冲突ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 安排ID
     */
    @Column(name = "assignment_id", nullable = false)
    private Long assignmentId;

    /**
     * 监考员ID
     */
    @Column(name = "invigilator_id", nullable = false)
    private Long invigilatorId;

    /**
     * 监考员姓名
     */
    @Column(name = "invigilator_name", length = 50, nullable = false)
    private String invigilatorName;

    /**
     * 冲突类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "conflict_type", length = 20, nullable = false)
    private AssignmentConflictType conflictType;

    /**
     * 冲突时间
     */
    @Column(name = "conflict_time", nullable = false)
    private LocalDateTime conflictTime;

    /**
     * 冲突描述
     */
    @Column(name = "conflict_description", columnDefinition = "TEXT")
    private String conflictDescription;

    /**
     * 严重程度
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "severity", length = 10, nullable = false)
    private AssignmentConflictSeverity severity;

    /**
     * 冲突状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "conflict_status", length = 20, nullable = false)
    private AssignmentConflictStatus conflictStatus;

    /**
     * 冲突影响评估
     */
    @Column(name = "impact_assessment", length = 500)
    private String impactAssessment;

    /**
     * 自动解决建议
     */
    @Column(name = "auto_solution_suggestion", columnDefinition = "TEXT")
    private String autoSolutionSuggestion;

    /**
     * 手动解决建议
     */
    @Column(name = "manual_solution_suggestion", columnDefinition = "TEXT")
    private String manualSolutionSuggestion;

    /**
     * 检测时间
     */
    @Column(name = "detected_time", nullable = false)
    private LocalDateTime detectedTime;

    /**
     * 检测方式
     */
    @Column(name = "detection_method", length = 50)
    private String detectionMethod;

    /**
     * 解决时间
     */
    @Column(name = "resolved_time")
    private LocalDateTime resolvedTime;

    /**
     * 解决人ID
     */
    @Column(name = "resolved_by", length = 32)
    private String resolvedBy;

    /**
     * 解决人姓名
     */
    @Column(name = "resolved_by_name", length = 50)
    private String resolvedByName;

    /**
     * 解决方案
     */
    @Column(name = "resolution", columnDefinition = "TEXT")
    private String resolution;

    /**
     * 解决备注
     */
    @Column(name = "resolution_remarks", length = 500)
    private String resolutionRemarks;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 监考安排关联
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "assignment_id", insertable = false, updatable = false)
    private InvigilationAssignment assignment;

    /**
     * 监考员关联
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "invigilator_id", insertable = false, updatable = false)
    private Invigilator invigilator;

    /**
     * 解决方案列表
     */
    @OneToMany(mappedBy = "conflict", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<ConflictSolution> solutions;
}